package org.zhadoop.stream.cql.semanticanalyzer.parser.context;

import java.util.List;

import org.zhadoop.stream.cql.exception.SemanticAnalyzerException;
import org.zhadoop.stream.cql.semanticanalyzer.analyzecontext.expressiondesc.ExpressionDescribe;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextreplacer.ParseContextReplacer;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextwalker.ParseContextWalker;

import com.google.common.collect.Lists;

/**
 * 
 * when 表达式解析内容
 * 
 * @author zwd
 *
 */
public class WhenExpressionContext extends BaseExpressionParseContext {

	// CaseWhenBodyWhenBodyContext
	private List<BaseExpressionParseContext> whens;

	// CaseWhenBodyThenBodyContext
	private List<BaseExpressionParseContext> thens;

	// CaseWhenElseContext
	private BaseExpressionParseContext elseExpression;

	@Override
	public void walkChildAndReplace(ParseContextReplacer replacer) {
		// TODO Auto-generated method stub

	}

	public WhenExpressionContext() {
		whens = Lists.newArrayList();
		thens = Lists.newArrayList();
	}

	@Override
	protected ExpressionDescribe createExpressionDesc() throws SemanticAnalyzerException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("CASE");
		for (int i = 0; i < whens.size(); i++) {
			sb.append(" " + whens.get(i).toString());
			sb.append(" ");
			sb.append(thens.get(i).toString());
		}
		if (elseExpression != null) {
			sb.append(" " + elseExpression.toString());
		}
		return sb.toString();
	}

	@Override
	protected void walkChild(ParseContextWalker walker) {
		// TODO Auto-generated method stub

	}

	public List<BaseExpressionParseContext> getWhens() {
		return whens;
	}

	public void setWhens(List<BaseExpressionParseContext> whens) {
		this.whens = whens;
	}

	public List<BaseExpressionParseContext> getThens() {
		return thens;
	}

	public void setThens(List<BaseExpressionParseContext> thens) {
		this.thens = thens;
	}

	public BaseExpressionParseContext getElseExpression() {
		return elseExpression;
	}

	public void setElseExpression(BaseExpressionParseContext elseExpression) {
		this.elseExpression = elseExpression;
	}
	
	

}
